package com.example.demo.prototype;

import java.util.Date;

/**
 * 原型模式，类实现Cloneable接口，重写clone()方法
 *      此方法为浅克隆，克隆之后如果圆型类中属性值修改，相应的克隆类属性也会发生变化
 *      可再重写clone()方法时，将可能会发生变化的属性也进行克隆，转化为深克隆
 */
public class Video implements Cloneable{

    private String name;
    private Date time;

    public Video() {
    }

    public Video(String name, Date time) {
        this.name = name;
        this.time = time;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }

    @Override
    public String toString() {
        return "Video{" +
                "name='" + name + '\'' +
                ", time=" + time +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        //重写clone()方法，连同属性值一起克隆
        Video video = (Video) super.clone();
        video.time = (Date) time.clone();
        return video;
    }
}
